import { getSetmealAPI } from "@/api/business/setmeal";
import { SetmealDishData, SetmealWithDishResult } from "@/types/setmeal";
import { ref } from "vue";

export default function (setmealId: number) {

  // 标题
  let title = ref('')
  let imageUrl = ref('')
  const setmealDishes = ref<SetmealDishData[]>([])
  const setmealForm = ref({} as SetmealWithDishResult)
  // 初始化
  const getSetmeal = async () => {
    try {
      if (setmealId) {
        title.value = '修改套餐'
        let res = await getSetmealAPI(setmealId)
        setmealForm.value = res.data
        imageUrl.value = res.data.image
        setmealDishes.value = res.data.setmealDishes
      } else {
        title.value = '添加套餐'
      }
    } catch (error) {
      console.log(error)
    }
  }
  return {
    title, imageUrl, setmealId, setmealDishes, setmealForm, getSetmeal
  }
}